//
//  LoginViewController.swift
//  Swift_SendMessage
//
//  Created by lanou3g on 15/11/25.
//  Copyright © 2015年 笨蛋一号后卫. All rights reserved.
//

import UIKit

class LoginViewController: UIViewController {
    var userNameTextField :UITextField?
    var passWordTextField : UITextField?
    override func viewDidLoad() {
        super.viewDidLoad()
        createView()
        
    }
    func createView() {
         self.userNameTextField = UITextField(frame: CGRectMake(10, 50, self.view.frame.size.width-20, 30))
        userNameTextField!.placeholder = "请输入用户名字"
        userNameTextField!.textAlignment = NSTextAlignment.Center
        userNameTextField!.textColor = UIColor.brownColor()
//        userNameTextField.backgroundColor = UIColor.grayColor()
        userNameTextField!.layer.cornerRadius = 3.0
        userNameTextField!.layer.borderWidth = 0.5
        self.view.addSubview(userNameTextField!)
        let loginButton = UIButton(type: UIButtonType.Custom)
        loginButton.frame = CGRectMake(10, 210, self.view.frame.size.width-20, 30)
        loginButton.backgroundColor = UIColor.magentaColor()
        loginButton.addTarget(self, action:Selector("loginButtonClicked") , forControlEvents: UIControlEvents.TouchUpInside)
        loginButton.titleLabel?.font = UIFont.boldSystemFontOfSize(15)
        loginButton.layer.cornerRadius = 5.0
        loginButton.setTitle("登录", forState: UIControlState.Normal)
        loginButton.setTitle("haha", forState: UIControlState.Highlighted)
        self.view.addSubview(loginButton)
        self.passWordTextField = UITextField(frame: CGRectMake(10, 100, self.view.frame.size.width-20, 30))
        passWordTextField!.placeholder = "请输入用户密码"
        passWordTextField!.textAlignment = NSTextAlignment.Center
        passWordTextField!.textColor = UIColor.brownColor()
        //        userNameTextField.backgroundColor = UIColor.grayColor()
        passWordTextField!.layer.cornerRadius = 3.0
        passWordTextField!.layer.borderWidth = 0.5
        self.view.addSubview(passWordTextField!)
        
//
        let registerButton = UIButton(type: UIButtonType.Custom)
        registerButton.frame = CGRectMake(10, 260, self.view.frame.size.width-20, 30)
        registerButton.backgroundColor = UIColor.magentaColor()
        registerButton.addTarget(self, action:Selector("registerButtonClicked") , forControlEvents: UIControlEvents.TouchUpInside)
        registerButton.setTitle("注册", forState: UIControlState.Normal)
        registerButton.setTitle("haha", forState: UIControlState.Highlighted)
        registerButton.titleLabel?.font = UIFont.boldSystemFontOfSize(15)
        registerButton.layer.cornerRadius = 5.0
        self.view.addSubview(registerButton)

        
    }
    func loginButtonClicked () {
       let loginHP = LoginHelper()
        loginHP.loginWithUser(self.userNameTextField!.text!, passWord: self.passWordTextField!.text!)
    }
    func registerButtonClicked() {
        let registerVC = RegisterViewController()
        self.presentViewController(registerVC, animated: true) { () -> Void in
            
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
